using ExampleWebApplication.Entities;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;

namespace ExampleWebApplication.Infraestruture.NHibernate.EntityMappings
{
    public class EmployeeMap : ClassMapping<Employee>
    {
        public EmployeeMap()
        {
            Table("Employees");
            Id(x => x.EmployeeID, map => { map.Generator(Generators.Identity); map.Column("EmployeeID"); });
            Property(x => x.LastName, map => { map.Column("LastName"); map.NotNullable(true); map.Length(20); });
            Property(x => x.FirstName, map => { map.Column("FirstName"); map.NotNullable(true); map.Length(10); });
            Property(x => x.Title, map => { map.Column("Title"); map.Length(30); });
            Property(x => x.TitleOfCourtesy, map => { map.Column("TitleOfCourtesy"); map.Length(25); });
            Property(x => x.BirthDate, map => map.Column("BirthDate"));
            Property(x => x.HireDate, map => map.Column("HireDate"));
            Property(x => x.Address, map => { map.Column("Address"); map.Length(60); });
            Property(x => x.City, map => { map.Column("City"); map.Length(15); });
            Property(x => x.Region, map => { map.Column("Region"); map.Length(15); });
            Property(x => x.PostalCode, map => { map.Column("PostalCode"); map.Length(10); });
            Property(x => x.Country, map => { map.Column("Country"); map.Length(15); });
            Property(x => x.HomePhone, map => { map.Column("HomePhone"); map.Length(24); });
            Property(x => x.Extension, map => { map.Column("Extension"); map.Length(4); });
            Property(x => x.Photo, map => { map.Column("Photo"); map.Length(2147483647); });
            Property(x => x.Notes, map => { map.Column("Notes"); map.Length(1073741823); });
            Property(x => x.PhotoPath, map => { map.Column("PhotoPath"); map.Length(255); });
            ManyToOne(x => x.ReportsTo, map => map.Column("ReportsTo"));
            Bag(x => x.Employees, map => { map.Inverse(true); map.Key(key => key.Column("ReportsTo")); }, rel => rel.OneToMany());
            Bag(x => x.EmployeeTerritories, map => { map.Inverse(true); map.Key(key => key.Column("EmployeeID")); }, rel => rel.OneToMany());
            Bag(x => x.Orders, map => { map.Inverse(true); map.Key(key => key.Column("EmployeeID")); }, rel => rel.OneToMany());
        }
    }
}
